/*
 * @Author: Shao_Yong_Qiang
 * @Date: 2021-05-18 09:24:49
 * @LastEditors: Shao_Yong_Qiang
 * @LastEditTime: 2021-05-18 11:18:23
 */

import React, { Component } from 'react'
// import { connect } from 'dva';
import {_getRouter} from '@/api/login';
import nav from '@/config/authorConfig'

const hocMenuTnterceptor = function (){
    return function(Com:any){
        class WarpComponent extends Component{
            state={
                listRouter:[],
            };
            componentDidMount(){
                // console.log(this.props)
                this.getListRouter()
            }

            async getListRouter(){
                let res = await _getRouter({user_id:localStorage.user_id})
                // console.log(nav,"askjdkasjdlk");
                let newArr:any=[];
                res.data.data.forEach((item:any)=>{
                    nav.find(item1=>{
                        if(item1.key==item.view_id){
                            newArr.push(item1)
                        }
                    })
                })
                console.log(newArr);
               this.setState({
                listRouter:newArr
               }) 
                // this.setState({listRouter:res.data.data},()=>{
                //     // console.log(nav)
                //     let menu:any = []
                //     this.state.listRouter.map((item:any) => {
                //         const arr = nav.find(list=> {
                //             return list.val === item.view_id
                //         })
                //         if(arr) menu.push(arr)
                //     })
                //     this.setState({list:menu})
                // })
            }
            render(){
                return <Com {...this.state} {...this.props}></Com>
            }
        }
        return WarpComponent
    }
}

export default hocMenuTnterceptor
